<?php
/**
 * post_publish插件
 */

include ADDON_PATH.'wc_post_publish/main/functions.php';
include ADDON_PATH.'wc_post_publish/main/ytrun.php';
class post_publish extends AWS_CONTROLLER
{
    
     protected $post_publish_plugin_info;
     protected $post_publish_plugin_config;
     protected $ytrun;
     /*定义使用的钩子*/
     public $hooks = ["app_begin",];
    
     public function __construct()
    {
        parent::__construct();
        $this->post_publish_plugin_info = get_hook_info('post_publish');
        $this->post_publish_plugin_config = get_plugins_config('post_publish');
        
       
        $this->ytrun = new ytrun(get_plugins_config('post_publish'));
    }
    
    /**
     * 安装前的业务处理，可在此方法实现，默认返回true
     * @return bool
     */
    public function install()
    {   
        // make_dir('post')
        return true;
    }

    /**
     * 卸载前的业务处理，可在此方法实现，默认返回true
     * @return bool
     */
    public function uninstall()
    {
        return true;
    }
    
    /**
     * 插件启用方法
     */
    public function enable()
    {
        return true;
    }

    /**
     * 插件禁用方法
     */
    public function disable()
    {
        return true;
    }
    
        /**
     * app_begin钩子方法
     * @param $params=[]
     */
    public function app_begin($params=[])
    {


        


        if($params['action'] == 'post_publish'){


            switch ($_GET['id']) {
                case 'article_post':
                    $this->ytrun->article_post();
                    break;
                case 'discussion_post':
                    $this->ytrun->discussion_post();
                    break;
                case 'category':
                    
                    $this->ytrun->category();
                    break;

                default:
                    # code...
                    break;
            }
           exit();    
        }
       
      

    }



    //获取版本信息的地址
    public function version_action() {
        $version = array(
            'protocol' => '1',
            'protocolVersion' => '1',
            'supportStdVersion' => array(
                'article' => '1.0.0',
                'question' => '1.0.0'
            ),
            'php' => PHP_VERSION,
            'supportVersion' => '3.0.0',
            'version' => '2.0.3',
            'pubVersion' => '1.2.0',
            'versionDetail' => array('wecenter' => G_VERSION), //set by this service
            'otherInfo' => array()
        );
        ta_success($version);
    }

    //验证方法
    private function validation() {
        if (empty($_POST['__sign'])) {

            ta_fail(TA_ERROR_INVALID_PWD, "password is empty", "发布密码为空");
        }

        $ta_config = array(
                'ta_password' => trim($this->post_publish_plugin_config['introduce_password']),
        );


        if ($_POST['__sign'] != $ta_config["ta_password"]) {
            ta_fail(TA_ERROR_INVALID_PWD, "password is wrong", "发布密码填写错误");
        }
    }










}